package com.santiao.youxiang.ui.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;


import com.santiao.youxiang.R;
import com.santiao.youxiang.databinding.FragmentCalculatorBinding;


import java.math.BigDecimal;

public class CalculatorFragment extends Fragment {
    FragmentCalculatorBinding binding;

    CalculatorViewModel viewModel;

    String groupingSeparatorSymbol = ",";
    String decimalSeparatorSymbol = ".";
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragmentCalculatorBinding.inflate(inflater, container, false);
        viewModel= new ViewModelProvider(this).get(CalculatorViewModel.class);
        binding.setLifecycleOwner(this);
        binding.setCam(viewModel);
        viewModel.setBinding(binding);
        observer();

        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        binding.pointButton.setImageResource(R.drawable.dot);
        super.onViewCreated(view, savedInstanceState);
        // 获取状态栏高度的资源 ID
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");

        // 如果资源 ID 有效，则获取状态栏高度
        if (resourceId > 0) {
            int statusBarHeight = getResources().getDimensionPixelSize(resourceId);
            binding.topBackground.getLayoutParams().height=statusBarHeight;
        } else {
            Log.d("StatusBarHeight", "无法获取状态栏高度");
        }
    }

    private void updateDisplay(View view, String value) {

    }
    @SuppressLint("SetTextI18n")
    private void observer() {
        viewModel.getResult().observe(getViewLifecycleOwner(), new Observer<BigDecimal>() {
            @Override
            public void onChanged(BigDecimal bigDecimal) {
                binding.resultDisplay.setText(bigDecimal.toString());
            }
        });

    }


}







